package org.massdgames.thunder.server.domain.strategy;

import java.util.ArrayList;

import org.massdgames.thunder.server.domain.Card;
import org.massdgames.thunder.server.domain.Deck;
import org.massdgames.thunder.server.domain.FetchException;

public class BasicStrategy implements FetchStrategy {

    protected int numberOfCardsToFetch = 1;
    
    public ArrayList<Card> getCards(Deck deck) throws FetchException {
        ensureParameterValidity(deck);

        ArrayList<Card> fetchedCards = new ArrayList<Card>();

        while (fetchedCards.size() < numberOfCardsToFetch) {
            fetchedCards.add(deck.getRandomCard());
        }

        return fetchedCards;
    }

    protected void ensureParameterValidity(Deck deck) {
        if (numberOfCardsToFetch < 1 || numberOfCardsToFetch > deck.getSize()) {
            throw new FetchException("Invalid card count: " + numberOfCardsToFetch);
        }
    }
    protected int getNumberOfCardsToFetch() {
        return numberOfCardsToFetch;
    }

    protected void setNumberOfCardsToFetch(int numberOfCardsToFetch) {
        this.numberOfCardsToFetch = numberOfCardsToFetch;
    }
}
